<template>
	<view class="container">
		<view class="lesson">
			<uni-forms ref="form" :model="form" labelWidth="80px" validateTrigger="bind">
				<uni-forms-item label="队员姓名" name="memberName">
					<uni-easyinput v-model="form.memberName" placeholder="请输入队员姓名" disabled />
				</uni-forms-item>
				<uni-forms-item label="手机号" name="phone">
					<uni-easyinput v-model="form.phone" placeholder="请输入手机号" disabled />
				</uni-forms-item>
				<uni-forms-item label="基础积分" name="integralBasic">
					<uni-easyinput v-model="form.integralBasic" type="number" placeholder="请输入基础积分" />
				</uni-forms-item>
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput v-model="form.remark" placeholder="请输入备注" />
				</uni-forms-item>
			</uni-forms>
			<button type="primary" @click="submit"
				style="color:#ffffff;backgroundColor:#993399;borderColor:#993399;">提交</button>
		</view>
	</view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import { updateMemberintegral } from "@/api/puyu/memberintegral";
	import { getDicts } from "@/api/system/dict/data";

	export default {
		data() {
			return {
				form: {
					memberName: "",
					phone: "",
					integralBasic: "",
					remark: ""
				},
				rules: {
					integralBasic: {
						rules: [{
							required: true,
							errorMessage: '基础积分不能为空'
						}]
					},
					memberName: {
						rules: [{ 
							required: true, 
							errorMessage: '队员姓名不能为空',
						}]
					},
					phone: {
						rules: [{
							required: true,
							errorMessage: '手机号不能为空'
						}, {
              pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
              errorMessage: '请输入正确的手机号码'
            }]
					},
				}
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onLoad(option) {
		  const item = JSON.parse(decodeURIComponent(option.item));
		  this.form = item;
		},
		methods: {
			checkPermi,
			checkRole,
			submit(ref) {
				this.$refs.form.validate().then(res => {
					updateMemberintegral(this.form).then(response => {
						this.$modal.msgSuccess("添加成功!")
						this.$tab.navigateBack();
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.lesson {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
	.same-name {
		margin-top: 15px;
		color: red;
	}
</style>